package test;




import dsa.*;




import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ChristianMarinTest {

	LinkedList list;
	ListIterator itr;

	@Before
	public void setUp() throws Exception  {
		list = new LinkedList();


		list.addLast(0);
		list.addLast(1);
		list.addLast(2);
		list.addLast(3);
		list.addLast(4);
		list.addLast(5);
		list.addLast(6);
		list.addLast(7);
		list.addLast(8);
		list.addLast(9);
		list.addLast(10);

		itr = list.listIterator(0);

	}

	@After
	public void tearDown() throws Exception {
		
	}
	/**
	 * Test ListIterator hasNext()
	 */
	@Test
	public void testHasNext(){
		assertTrue(itr.hasNext() == true);
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		assertTrue(itr.hasNext() == false);
			
	}
	/**
	 * Test ListIterator hasPrevious()
	 */
	@Test
	public void testHasPrevious(){
		assertTrue(itr.hasPrevious() == false);
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		assertTrue(itr.hasPrevious() == true);
			
	}
	/**
	 * Test ListIterator next()
	 */
	@Test
	public void testItrNext(){

		
		for(int i = 0; i < list.size(); i++){
			assertTrue(list.get(i).equals(itr.next()));
		}
		
	}
	/**
	 * Test ListIterator previous()
	 */
	@Test
	public void testItrPrevious(){
		
		assertTrue(itr.next().equals(0));
		assertTrue(itr.previous().equals(0));
		assertTrue(itr.next().equals(0));
		assertTrue(itr.next().equals(1));
		assertTrue(itr.previous().equals(1));
			
	}
	/**
	 * Test ListIterator nextIndex()
	 */
	@Test
	public void testNextIndex(){
		assertTrue(itr.nextIndex()==0);
		itr.next();
		assertTrue(itr.nextIndex()==1);
		itr.next();
		assertTrue(itr.nextIndex()==2);
		itr.next();
		assertTrue(itr.nextIndex()==3);
		itr.next();
		assertTrue(itr.nextIndex()==4);
		
	}
	/**
	 * Test ListIterator previousIndex()
	 */
	@Test
	public void testPreviousIndex(){
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		assertTrue(itr.previousIndex()==4);
		itr.previous();
		assertTrue(itr.previousIndex()==3);
		itr.previous();
		assertTrue(itr.previousIndex()==2);
		itr.previous();
		assertTrue(itr.previousIndex()==1);
		itr.previous();
		assertTrue(itr.previousIndex()==0);
		
	}
	/**
	 * Test ListIterator add()
	 */
	@Test
	public void testAdd(){
		
		
		itr.add(-1);
		itr.next();
		itr.next();
		itr.add(-3);
		
		assertTrue(list.get(0).equals(-1));
		assertTrue(list.get(1).equals(0));
		assertTrue(list.get(2).equals(1));
		assertTrue(list.get(3).equals(-3));
		assertTrue(list.get(4).equals(2));
		assertTrue(list.get(5).equals(3));
		assertTrue(list.get(6).equals(4));
		assertTrue(list.get(7).equals(5));
		assertTrue(list.get(8).equals(6));
		assertTrue(list.get(9).equals(7));
		assertTrue(list.get(10).equals(8));
		assertTrue(list.get(11).equals(9));
		assertTrue(list.get(12).equals(10));
		
	}
	/**
	 * Test ListIterator remove()
	 */
	
	@Test
	public void testRemoveItr(){
		
		itr.next();
		itr.next();
		itr.remove();
		itr.next();
		itr.next();
		itr.remove();
		
		assertTrue(list.get(0).equals(0));
		assertTrue(list.get(1).equals(2));
		assertTrue(list.get(2).equals(4));
		assertTrue(list.get(3).equals(5));
		assertTrue(list.get(4).equals(6));
		assertTrue(list.get(5).equals(7));
		assertTrue(list.get(6).equals(8));
		assertTrue(list.get(7).equals(9));
		assertTrue(list.get(8).equals(10));
		
	}
	/**
	 * Test ListIterator set()
	 */
	@Test
	public void testItrSet(){
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.next();
		itr.set(-4);
		
		assertTrue(list.get(0).equals(0));
		assertTrue(list.get(1).equals(1));
		assertTrue(list.get(2).equals(2));
		assertTrue(list.get(3).equals(3));
		assertTrue(list.get(4).equals(-4));
		assertTrue(list.get(5).equals(5));
		assertTrue(list.get(6).equals(6));
		assertTrue(list.get(7).equals(7));
		assertTrue(list.get(8).equals(8));
		assertTrue(list.get(9).equals(9));
		assertTrue(list.get(10).equals(10));
		
	}
	
	/**
	 * Test the addFirst method and checks size
	 */
	@Test
	public void testAddFirst() {


		list.addFirst(-1);
		list.addFirst(-2);
		list.addFirst(-3);
		list.addFirst(-4);
		list.addFirst(-5);
		assertTrue (list.get(0).equals(-5));
		assertTrue (list.get(1).equals(-4));
		assertTrue (list.get(2).equals(-3));
		assertTrue (list.get(3).equals(-2));
		assertTrue (list.get(4).equals(-1));
		assertTrue (list.size()==(16));

	}
	/**
	 * Test the get method

	@Test
	public void testGet(){
		System.out.println("-----------");
		for(int i = 0; i <= list.size()-1; i++){
			System.out.println(list.get(i));
			}
		System.out.println("-----------");
	}
	 */

	/**
	 * Test the remove first method and checks size
	 */
	@Test
	public void testRemoveFirst(){
		list.removeFirst();
		list.removeFirst();
		assertTrue (list.get(0).equals(2));
		assertTrue (list.get(1).equals(3));
		assertTrue (list.size()==(9));
	}
	/**
	 * Test the remove last method and checks size
	 */
	@Test
	public void testRemoveLast(){
		list.removeLast();
		list.removeLast();
		assertTrue (list.get(8).equals(8));
		assertTrue (list.indexOf(9)==(-1));
		assertTrue (list.indexOf(10)==(-1));
		assertTrue (list.size()==(9));


	}
	/**
	 * Tests the remove method and checks size
	 */
	@Test
	public void testRemove(){
		list.remove(3);
		list.remove(7);


		assertTrue (list.get(0).equals(0));
		assertTrue (list.get(1).equals(1));
		assertTrue (list.get(2).equals(2));
		assertTrue (list.get(3).equals(4));
		assertTrue (list.get(4).equals(5));
		assertTrue (list.get(5).equals(6));
		assertTrue (list.get(6).equals(7));
		assertTrue (list.get(7).equals(9));
		assertTrue (list.get(8).equals(10));
		assertTrue (list.size()==(9));



	}
	/**
	 * Tests the size method
	 */
	@Test
	public void testSize(){
		assertTrue (list.size()==11);
	}
	/**
	 * Tests the indexOf method 
	 * 
	 */
	@Test
	public void testIndexOf(){
		assertTrue (list.indexOf(0)==0);
		assertTrue (list.indexOf(1)==1);
		assertTrue (list.indexOf(2)==2);
		assertTrue (list.indexOf(3)==3);
		assertTrue (list.indexOf(4)==4);
		assertTrue (list.indexOf(5)==5);
		assertTrue (list.indexOf(-1)==-1);
		assertTrue (list.indexOf(59)==-1);
	}
	/**
	 * Tests the contains method
	 */
	@Test
	public void testContains(){
		assertTrue (list.contains(0)==true);
		assertTrue (list.contains(1)==true);
		assertTrue (list.contains(2)==true);
		assertTrue (list.contains(3)==true);
		assertTrue (list.contains(4)==true);
		assertTrue (list.contains(5)==true);
		assertTrue (list.contains(6)==true);
		assertTrue (list.contains(-1)==false);
		assertTrue (list.contains(25)==false);
	}
	/**
	 * Tests the getFirst method
	 */
	@Test
	public void testGetFirst(){
		assertTrue (list.getFirst().equals(0));

	}
	/**
	 * Tests the getLast method
	 */
	@Test
	public void testGetLast(){
		assertTrue (list.getLast().equals(10));
	}

	/**
	 * Test the Clone method
	 */
	@Test
	public void testClone(){
		LinkedList list2 = (LinkedList) list.clone();

		for(int i = 0; i < list.size(); i++){
			assertTrue(list.get(i).equals(list2.get(i)));
		}
	}

	/**
	 * Test the set method
	 */
	@Test
	public void testSet(){
		list.set(0, 5);
		list.set(9, 20);
		list.set(5, 15);
		assertTrue (list.getFirst().equals(5));
		assertTrue (list.get(9).equals(20));
		assertTrue (list.get(5).equals(15));
	}

	/**
	 * Test toArray method
	 */
	@Test
	public void testToArray(){
		Object array[] = new Object[list.size()];
		array = list.toArray();
		for(int i = 0; i < array.length; i++){
			assertTrue(list.get(i).equals(array[i]));
		}
	}


}
